﻿/**
 * @Description 基础框架服务调用实例-数据服务-普通参数
 *@Author  guoyanfei
 */

var serviceUrl = '/gdp'
var commServices = commServices || {};
commServices.prototype = {
    init: function () {//表格初始化
        $("#sv_content").append(JSON.stringify(commServices.prototype.getJson()));
    },
    getJson: function () {//调用服务
        var jsonData = "";
        $.ajax({
            url: serviceUrl + '/business/execute/executeQuery',
            type: 'post',
            async: false,
            data: { serviceID: serviceId },
            dataType: "json",
            success: function (data) {
                jsonData = data;
            },
            error: function () {
                bootbox.alert("数据加载失败!");
            }
        });
        return jsonData;
    },
    generateTable: function () {//生成表格
        var jsonData = commServices.prototype.getJson();
        var json = jsonData.rows;
        var htmls=['<table class=\"table table-hover table-striped\">'];   
            htmls.push('<tr>')  
            for (var k in json[0])
                htmls.push('<td>' + k + '</td>');
            htmls.push('</tr>');
            for (var i = 0, L = json.length; i < L; i++) {
                htmls.push('<tr>');
                for (var k in json[i])
                    htmls.push('<td>' + json[i][k] + '</td>');
                htmls.push('</tr>');
            }
            htmls.push('</table>');
            $('#tb_content').html(htmls.join(''));
    }
};

//服务初始化
$(function () {
    $("#sp_seviceUrl").append("服务地址：" + serviceUrl + "/business/execute/executeQuery");
    $("#sp_seviceUrl").append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;服务ID：" + serviceId);

    var comm = commServices.prototype;
    comm.init();
    comm.generateTable();
})
